@echo off
REM 直接安装AI服务核心依赖并启动服务

cd /d "%~dp0ai"

REM 创建虚拟环境
if not exist ".venv" (
  echo Creating Python virtual environment...
  python -m venv .venv
)

REM 激活虚拟环境
echo Activating virtual environment...
call .venv\Scripts\activate.bat

REM 先安装核心依赖
echo Installing core dependencies...
pip install fastapi uvicorn[standard]

REM 安装其他依赖（除了可能有问题的Pillow）
echo Installing other dependencies...
set packages=langchain langchain-community chromadb sentence-transformers pydantic python-multipart aiofiles pypdf openai python-docx docx2txt
for %%i in (%packages%) do (
  pip install %%i
)

REM 尝试安装较新的Pillow版本
echo Installing Pillow...
pip install pillow==11.0.0

REM 设置环境变量
echo Setting environment variables...
set "QWEN_API_KEY=sk-77fea248756e43b5a3bb63838dd2da24"
set "DASHSCOPE_API_KEY=%QWEN_API_KEY%"
set "AI_HOST=0.0.0.0"
set "AI_PORT=8000"
set "AI_CORS_ORIGINS=http://localhost:5173,http://localhost:8080"

REM 启动AI服务
echo Starting AI service...
python main.py